home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga CD-ROM Collection
/
Amiga CD-ROM Collection - Auge 4000 and Cactus and Demo Util.iso
/
auge4000
/
15
/
späße
/
lpem.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-01-20
|
5KB
|
196 lines
/* I know I stole a bunch of this source off of somebody, but I've
forgotten who it is. If this looks familiar, sorry, but I've
forgotten who you are. */
#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <graphics/sprite.h>
#include <exec/tasks.h>
struct Preferences MyPrefs;
struct RastPort *RP;
struct IntutitionBase *IntuitionBase;
struct GfxBase *GfxBase;
unsigned short color[3];
int red[3], green[3], blue[3];
#define NUM 6
#define SPRHEIGHT 16
#define WORDSPERSPR (2 * SPRHEIGHT + 4)
#define ever (;;)
struct NewWindow windef = {
0, 15, 300, 10,
-1, -1,
CLOSEWINDOW,
REPORTMOUSE | WINDOWCLOSE | WINDOWDEPTH | WINDOWDRAG,
NULL, NULL,
(UBYTE *) "Wait...",
NULL, NULL, 0, 0, 0, 0,
WBENCHSCREEN
};
struct SimpleSprite spr[NUM];
struct Window *win;
struct ViewPort *vp;
UWORD *sprbuf;
UWORD *sprites[NUM];
main (argc, argv)
int argc;
char *argv[];
{
int i,j, offset = 0, flag = 0;
void *msg;
BYTE Count;
openstuff ();
RP = (struct RastPort *)win.RPort;
Count = 1;
if (argc > 1)
{
Count = atoi(argv[1]);
if ((Count > 10) | (Count == 0))
{
printf("Usage: %s count (1-10)\n", argv[0]);
Count = 1;
};
};
color[1] = (USHORT) MyPrefs.color17;
color[2] = (USHORT) MyPrefs.color18;
color[3] = (USHORT) MyPrefs.color19;
for (i = 1; i <=3; i++)
{
red[i] = (color[i] >> 8) & 0x0F;
green[i] = (color[i] >> 4) & 0x0F;
blue[i] = color[i] & 0x0F;
}
for (i = 17; i < 31; i = i + 4)
{
SetRGB4(vp, i, red[1], green[1], blue[1]);
SetRGB4(vp, i+1, red[2], green[2], blue[2]);
SetRGB4(vp, i+2, red[3], green[3], blue[3]);
};
setupsprites ();
for (i=0; i<NUM; i++) {
if (GetSprite (&spr[i], (long) i+1) < 0)
die ("LPem: Sprite allocation failed.");
spr[i].x = 640 / 2;
spr[i].y = 10;
spr[i].height = SPRHEIGHT;
ChangeSprite (vp, &spr[i], sprites[i]);
}
SetWindowTitles (win, " Long Persistence Emulator ", "By Steve Tibbett");
for ever {
if (msg = GetMsg (win -> UserPort)) {
ReplyMsg (msg);
if (msg->Class == CLOSEWINDOW)
{
closestuff ();
return;
};
};
for (i=0; i<NUM; i++)
{
for (j = 0; j < Count; j++) WaitTOF();
spr[NUM-i-1].x = (win->MouseX + win->LeftEdge + MyPrefs.XOffset);
spr[NUM-i-1].y = (win->MouseY + win->TopEdge + MyPrefs.YOffset - 1);
ChangeSprite (vp, &spr[NUM-i-1], sprites[NUM-i-1]);
}
}
}
openstuff ()
{
IntuitionBase = OpenLibrary ("intuition.library", 0);
/* Geez, guys, what if Intuition isn't here? Who cares? We're
probably all dead anyways, if this happens... */
GfxBase = OpenLibrary ("graphics.library", 0);
/* Ya, sure, you've pulled the Graphics.Library ROM out, right? */
if (!(win = OpenWindow (&windef)))
die ("LPem: No memory for window");
GetPrefs(&MyPrefs, sizeof(struct Preferences));
vp = ViewPortAddress (win);
}
closestuff ()
{
register int i;
for (i=0; i<NUM; i++)
if (spr[i].num)
FreeSprite ((long) spr[i].num);
if (sprbuf)
FreeMem (sprbuf, 2L * WORDSPERSPR * NUM);
if (win)
CloseWindow (win);
if (GfxBase)
CloseLibrary (GfxBase);
if (IntuitionBase)
CloseLibrary (IntuitionBase);
}
die (str)
char *str;
{
puts (str);
closestuff ();
exit (100);
}
int i;
setupsprites ()
{
/* This is what I stole. Boy, I hope it wasn't copyrighted... */
UWORD *cw;
UWORD *maskp;
UWORD *ballp, *ballp2;
int frame, scan;
if (!(sprbuf = AllocMem (2L * WORDSPERSPR * NUM, MEMF_CHIP)))
die ("LPem: Can't allocate sprite buffer.");
cw = sprbuf; /* current position at top of buffer */
ballp = &MyPrefs.PointerMatrix[0]; /* ... top of data to be interleaved */
ballp2 = ballp;
for (frame=0; frame<NUM; frame++) {
maskp = 1; /* one mask for all frames */
sprites[frame] = cw;
*cw++ = 0; /* poscntl */
*cw++ = 0;
ballp=ballp2;
/* one word from ball0, one word from ballmask */
for (scan=0; scan<SPRHEIGHT; scan++) {
*cw++ = *ballp++;
*cw++ = *ballp++;
}
*cw++ = 0; /* termination */
*cw++ = 0;
}
}